using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// Summary description for processFeedback
/// </summary>
public class processFeedback:DBConnectionTool
{
	public processFeedback() : base()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    //getFeedbackID method used to general FeedbackID automatically
    public string getFeedbackID()
    {
        OpenCn();
        SqlCommand cmd = new SqlCommand("Select right (max(FeedbackID),4) from Feedbacks", cn);
        String s = cmd.ExecuteScalar().ToString();
        Int32 result;
        if (Int32.TryParse(s,out result))
            result++;
        else
            result=1;
        int l = result.ToString().Length;
        int count = 4 - l;
        string sresult = "Fee";
        for (int i = 0; i < count; i++)
        {
            sresult = sresult + "0";
        }
        sresult = sresult + result;
        CloseCn();        
        return sresult;
    }
    public DataTable ListFeedback()
    {
        OpenCn();
        SqlDataAdapter da = new SqlDataAdapter("select * from Feedbacks", cn);
        DataTable dt = new DataTable("Feedbacks");
        da.Fill(dt);
        CloseCn();
        return dt;
    }

    public string getFeedbackDetailByID(string FeedbackID)
    {
        OpenCn();
        SqlCommand cmd = new SqlCommand("select FeedbackDetail from Feedbacks where FeedbackID = '" + FeedbackID + "'", cn);
        string result = cmd.ExecuteScalar().ToString();
        CloseCn();
        return result;
    }
    //insertFeedback method used to add new Feedbacks
    public int insertFeedback(string FeedbackID,string FeedbackEmail, string FeedbackName, string FeedbackDetail)
    {
        try
        {
            OpenCn();
            SqlCommand cmd = new SqlCommand("Insert Into Feedbacks(FeedbackID,FeedbackEmail,FeedbackName,FeedbackDetail) Values(@FeedbackID,@FeedbackEmail,@FeedbackName,@FeedbackDetail)", cn);
            cmd.Parameters.Add(new SqlParameter("@FeedbackID", SqlDbType.Char, 7));
            cmd.Parameters.Add(new SqlParameter("@FeedbackEmail", SqlDbType.VarChar, 200));
            cmd.Parameters.Add(new SqlParameter("@FeedbackName", SqlDbType.NVarChar, 200));
            cmd.Parameters.Add(new SqlParameter("@FeedbackDetail", SqlDbType.NVarChar, 500));
            cmd.Parameters["@FeedbackID"].Value = FeedbackID;
            cmd.Parameters["@FeedbackEmail"].Value = FeedbackEmail;
            cmd.Parameters["@FeedbackName"].Value = FeedbackName;
            cmd.Parameters["@FeedbackDetail"].Value = FeedbackDetail;
            int result = cmd.ExecuteNonQuery();
            CloseCn();
            return result;
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
            
        }
    }
    public int deleteFeedback(string FeedbackID)
    {
        OpenCn();
        SqlCommand cmd = new SqlCommand("Delete Feedbacks Where FeedbackID ='" + FeedbackID + "'", cn);
        int result = cmd.ExecuteNonQuery();
        CloseCn();
        return result;
    }
}
